using System;
using System.Diagnostics;
using System.Reflection;
using System.Text;

namespace Assets.Scripts.GDK
{
	public class gdk_safeCall
	{
		public delegate void SafeFunc();

		private static DateTime _start = DateTime.Now;

		public static int Tick => (int)(DateTime.Now - _start).TotalMilliseconds;

		public static string GetFunctionName(string con = "")
		{
			StringBuilder name = new StringBuilder();
			Call(delegate
			{
				if (0 == 0)
				{
					StackTrace stackTrace = new StackTrace();
					StackFrame frame = stackTrace.GetFrame(1);
					MethodBase method = frame.GetMethod();
					string name2 = method.ReflectedType.Name;
					if (name2.Equals("Common") && method.Name.Equals("SafeCall"))
					{
						name.Append("堆栈:").Append(stackTrace.ToString()).Append("------>>")
							.Append(con);
					}
					else
					{
						name.Append(name2).Append(".").Append(method.Name)
							.Append("------>>")
							.Append(con);
					}
				}
			});
			return name.ToString();
		}

		public static void Call(SafeFunc f, SafeFunc fError = null)
		{
			try
			{
				f?.Invoke();
			}
			catch (Exception)
			{
				fError?.Invoke();
			}
		}
	}
}
